﻿$(function(){
});

//移除空内容区域
function RemoveNull(d,t){
	if (!$(d).find(t).is(t)){$(d).remove();}
}

//Product Show
function ProductShow(){
	$(window).scroll(function(){
		if ($(window).scrollTop()>257){
			$("#ProductKind").css({"top":$(window).scrollTop()-257});
		}else{
			$("#ProductKind").css({"top":"auto"});
		}
	});
}

//Follow Bar
(function($){
	$.fn.followBar = function(options){
		var defaults = {}
		var options = $.extend(defaults,options);
		this.each(function(){
			var obj = $(this), t = obj.offset().top;
			window.onscroll = function(){f(obj,t)};
			window.onresize = function(){f(obj,t)};
			
			function f(obj,t){
				var dst = $(document).scrollTop();
				if(($.browser.msie == true) && ($.browser.version == 6.0)){
					if(dst > t) obj.css({position: "absolute", top: dst - t});
				}else{
					if(dst > t) obj.css({position: "fixed", top: "-" & dst + "px"});
				}
				if(dst <= t) obj.css({position: "static", top: 0});
			}
		});
		
	}
})(jQuery);

//Recent News
function RecentNews(u){
	$("#RecentNews").hide();
	$("#RecentNews").load(u+"?t=" + Math.random(),function(){
		setInterval("ScrollList('#RecentNews')",5000);
		$("#RecentNews").show("fast");
	});
}

//顶部滚动新闻
function ScrollList(obj){
	if ($(obj).find("ul:first li").length>1){
		$(obj).find("ul:first").animate({marginTop:"-30px"},500,function(){
			$(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
		});
	}
}

//菜单状态选择
function menuSelect(){
	var MenuLink,TabsText,NavLink=$("#Nav a:eq(1)").attr("href");
	var MenuText,NavText=$("#Nav strong").html();
	
	if ($("#Nav").length>0){
		$("#Menu li").each(function(){
			MenuLink=$(this).children("a").attr("href");
			MenuText=$(this).find("span").html();
			if (MenuLink==NavLink || MenuText==NavText) $(this).addClass("s");
		});
	}else{
		$("#Menu li:eq(0)").addClass("s");
	}
}

//搜索条
function searchBar(t){
	var formDom=$("#SiteSearch"),inputDom=$("#SiteSearch>.inpt");
	var searchKey=inputDom.val();
	if (inputDom.val()!=""){
		inputDom.val()=t;
	}
	inputDom.focus();
	formDom.submit(function(){
		if (inputDom.val()==""){
			return false;
		}
	});
}

/*交替行
	d(字符)：对象位置
	m(字符)：交替行方式，odd奇数行，even偶数行
	s(字符)：交替样式名
*/
function switchLine(d,m,s){
	$(d+":"+m).addClass(s);
}

/*切换栏
	i(数字)：默认显示项目,0为第一个
	t(字符)：标题列表
	c(字符)：内容列表
	s(字符)：标题选中样式
	m(字符)：触发方式：
		mouseover：鼠标移动
		click：鼠标点击
*/
function tabs(i,t,c,s,m){
	//初始化显示
	$(t).eq(i).addClass(s);
	$(c).eq(i).show().siblings().hide();
	//切换
	var _index;
	$(t).bind(m,function(){
		$(this).addClass(s).siblings().removeClass(s);
		_index=$(t).index($(this));
		$(c).eq(_index).show().siblings().hide();
	});
}

//文字大小缩放
function zoomText(dom,textclass){
	$(dom).removeClass();
	$(dom).addClass(textclass);
}

//水平滚动插件
(function($){
	$.fn.easyScroll = function(options){
		var defaults = {
			controlsShow:	true,
			prevId:			"prevBtn",
			prevText:		"",
			nextId:			"nextBtn",
			nextText:		"",
			speed:			500,
			pause:			3600,
			auto:			true,
			titleTip:		true,
			offset:			0
		}
		var options = $.extend(defaults,options);
		this.each(function(){
			var obj = $(this);
			var s = $("li", obj).length;
			var w = $("li", obj).outerWidth(true);
			
			//滚屏内容宽度
			$("ul", obj).css("width", w*s);
			
			//滚屏按钮
			if(options.controlsShow){
				var html = "";
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				$(obj).append(html);
				function btnBind(){
					$("a","#"+options.nextId).click(function(){		
						animate("next",true);
					});
					$("a","#"+options.prevId).click(function(){		
						animate("prev",true);				
					});	
				}
				btnBind();
			}
			
			//滚屏动画
			function animate(dir,clicked){
				switch(dir){
					case "next"://前进
						$("ul", obj).animate({marginLeft:-options.offset},options.speed,function(){
							$(this).css({marginLeft:0}).find("li:first").appendTo(this);
						});
						break; 
					case "prev"://后退
						$("ul", obj).prepend($("ul", obj).css({marginLeft:-options.offset}).find("li:last"));
						$("ul", obj).animate({marginLeft:0},options.speed);
						break;
					default:
						break;
				};
				
				//取消自动滚屏
				if(clicked) clearTimeout(timeout);
				
				//自动滚屏
				if(!clicked){
					timeout = setTimeout(function(){
						animate("next",false);
					},options.pause);
				};
			}
			
			//提示
			if(options.titleTip){
				$("ul li", obj).each(function(){
					var t = $(this).find("img").attr("alt");
					$(this).find("img").attr("alt","");
					$(this).append("<div class='tip'>"+t+"</div>");
					$(this).find(".tip").hide();
					$(this).hover(
						function(){
							$(this).find(".tip").show();
						},
						function(){
							$(this).find(".tip").hide();
						}
					);
				});
			};
			
			//开始自动滚屏
			var timeout;
			if(options.auto){
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};
		});
	}
})(jQuery);

//正文提示
function egg(e){if(typeof window.k=="undefined"){window.k=""}var e=e||event;if(e.keyCode==116) window.k="";window.k+=e.keyCode+",";if(window.k=="38,38,40,40,37,37,39,39,"){alert(unescape("%u9ED1%u9ED1%u5236%u9020"));window.k="";}}document.onkeydown=egg;

//提示后跳转
function SureDo(src,q){
	var ret;
	ret=confirm(q);
	if(ret!=false)window.location=src;
}

//加入收藏
function AddBookmark(title, url){
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL'; 
if(jQuery.browser.msie){
		window.external.AddFavorite(url, title);
	}else if (document.all){
		window.external.addFavorite(url,title);
	}else if (window.sidebar){
		window.sidebar.addPanel(title, url, "");
	}else{
		alert("You can try the shortcut keys Ctrl + D to add to Favorites"); 
	}
}

//设为首页
function SetHome(obj,url){
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
	}
	catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch(e){
				suredo("help.html#sethome","When a browser page can not be set if View help information?");
			}
			var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);
		}
	}
}

//信息替换
function ChangeInfo(obj,oldinfo,newinfo){
	if ($(obj).text()==oldinfo){
		$(obj).html(newinfo);
	}
}